﻿Ext.override(NExt.UI.Find.Base.FindPresenterBase, {

    templateInitializeEvents: function() {
        NExt.UI.Find.Base.FindPresenterBase.superclass.templateInitializeEvents.call(this);
        this.addEvents('beforeOk', 'afterOk');
        this.addEvents('beforeCancel', 'afterCancel');
        this.addEvents('afterFind');
    },

    fireOk: function() {
        this.fireEvent('beforeOk');
        this.templateOk();
        this.fireEvent('afterOk');
    },

    templateOk: function() {
        var model = this.getCurrentModel();
        this.fireEvent('afterFind', model);
        this.fireClose();
    },

    fireCancel: function() {
        this.fireEvent('beforeCancel');
        this.templateCancel();
        this.fireEvent('afterCancel');
    },

    templateCancel: function() {
        this.fireClose();
    },

    find: function(current, callback, scope) {
        this.setCallback(callback, scope);
        this.setCurrentModel(current);
        this.fireShow();
    },

    setCallback: function(callback, scope) {
        if (callback) {
            this.on('afterFind', callback, scope, { single: true });
        }
    },

    getCurrentModel: Ext.emptyFn,
    setCurrentModel: Ext.emptyFn
});
